﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;

namespace ZHDJ.WebPage.Picker
{
    [DefaultEvent("TriggerClick")]
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:TriggerBoxPicker Label=\"Label\" TriggerIcon=\"Search\" runat=\"server\"></{0}:TriggerBoxPicker>")]
    public class TriggerBoxPicker : TwinTriggerBox
    {
        /// <summary>
        /// 窗体地址
        /// </summary>
        [DefaultValue(false)]
        [Description("窗体地址")]
        public string WindinsUrl
        {
            get
            {
                object obj = FState["WindinsUrl"];
                return obj.ToString();
            }
            set
            {
                FState["WindinsUrl"] = value;
            }
        }

        /// <summary>
        /// 窗体标题
        /// </summary>
        [DefaultValue(false)]
        [Description("窗体标题")]
        public string WindinsTitle
        {
            get
            {
                object obj = FState["WindinsTitle"];
                return obj.ToString();
            }
            set
            {
                FState["WindinsTitle"] = value;
            }
        }

        /// <summary>
        /// 窗体宽度
        /// </summary>
        [DefaultValue(650)]
        [Description("窗体宽度")]
        public Unit WindinsWidth
        {
            get
            {
                object obj = FState["WindinsWidth"];
                return Unit.Parse(obj.ToString());
            }
            set
            {
                FState["WindinsWidth"] = value;
            }
        }

        /// <summary>
        /// 窗体高度
        /// </summary>
        [DefaultValue(450)]
        [Description("窗体高度")]
        public Unit WindinsHeight
        {
            get
            {
                object obj = FState["WindinsHeight"];
                return Unit.Parse(obj.ToString());
            }
            set
            {
                FState["WindinsHeight"] = value;
            }
        }

        [DefaultValue(true)]
        public bool EnablePicker
        {
            get
            {
                object obj = FState["EnablePicker"];
                return obj == null || Convert.ToBoolean(obj);
            }
            set
            {
                FState["EnablePicker"] = value;
            }
        }

        /// <summary>
        /// picker值
        /// </summary>
        [DefaultValue(false)]
        [Description("picker值")]
        public string Value
        {
            get
            {
                var hiddenField = ControlUtil.FindControl(this.ID + "hidden") as FineUI.HiddenField;
                return hiddenField.Text;
            }
            set
            {
                var hiddenField = ControlUtil.FindControl(this.ID + "hidden") as FineUI.HiddenField;
                hiddenField.Text = value;
            }
        }

        /// <summary>
        /// 清空值js
        /// </summary>
        /// <returns></returns>
        public string ClearValueJS()
        {
            var hiddenField = ControlUtil.FindControl(this.ID + "hidden") as FineUI.HiddenField;
            StringBuilder js = new StringBuilder();
            js.AppendFormat(@"
                ; var pickerClientID = '{0}';
                  var pickerHdClientID = '{1}';
                  F(pickerClientID).setValue('');
                  F(pickerHdClientID).setValue('');
", this.ClientID, hiddenField.ClientID);
            return js.ToString();
        }
    }
}